using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NiSis.Data;
using NiSis.Entities;

namespace NiSis.UserControls
{
    public partial class SocietaPicker : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
       

        public bool HasRelations
        {
            get 
            {
                return (LstSocieta.Items.Count > 0 && LstSocieta.SelectedIndex != -1);
            }
            
        }
	
        protected void UpdateList()
        {
            if (txtSearch.Text.Length == 0)
                return;

            VList<VSocietaAll> lSoc = DataRepository.VSocietaAllProvider.Get(string.Format("ds_societa like '{0}%' and Cd_Societa<>'new'", txtSearch.Text),"ds_societa");
            LstSocieta.DataSource = lSoc;
            LstSocieta.DataBind();
        }

        protected void cmdSearch_Click(object sender, ImageClickEventArgs e)
        {
            UpdateList();
        }

        public string DsSocieta()
        {
            return LstSocieta.SelectedItem.Text;
        }

        public string CdSocieta()
        {
            return LstSocieta.SelectedValue;
        }

        public int IdTipologiaSocieta()
        {
            if (LstSocieta.Items.Count==0 || LstSocieta.SelectedIndex == -1)
                return 0;

            if (LstSocieta.SelectedItem.Text.Contains("(Shipper"))
                return 2;
            if (LstSocieta.SelectedItem.Text.Contains("(Trader"))
                return 1;
            if (LstSocieta.SelectedItem.Text.Contains("(New Trader"))
                return 3;
            if (LstSocieta.SelectedItem.Text.Contains("(New Shipper"))
                return 4;

            return 0;
        }

        protected void cdmReset_Click(object sender, ImageClickEventArgs e)
        {
            LstSocieta.Items.Clear();
        }

    }
}